package com.ruoyi.web.controller.system;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;

import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.framework.service.AccessTokenService;
import com.ruoyi.framework.service.SysLoginService;
import com.ruoyi.framework.shiro.LoginForm;
import com.ruoyi.system.domain.SysUser;

/**
 * <p>File：SysLoginController.java</p>
 * <p>Title: 登陆验证</p>
 * <p>Description:</p>
 * <p>Copyright: Copyright (c) 2019 2019年7月17日 下午6:19:43</p>
 * <p>Company:  </p>
 * @author zmr
 * @version 1.0
 */
@RestController
public class SysLoginController extends BaseController
{
    @Autowired
    private SysLoginService    loginService;

    @Autowired
    private AccessTokenService tokenService;

    @PostMapping("/login")
    public R ajaxLogin(LoginForm loginForm)
    {
        SysUser user = loginService.login(loginForm.getUsername(), loginForm.getPassword());
        return R.success(tokenService.createToken(user.getUserId(), user.getLoginName(), user.getPassword()));
    }
}
